package DS0507;

public class Main {
    public static void main(String args[]){
     TreeNode D = new TreeNode('D',null,null);
        TreeNode E = new TreeNode('E',null,null);
        TreeNode F = new TreeNode('F',null,null);
        TreeNode B = new TreeNode('B',D,E);
        TreeNode C = new TreeNode('C',null,F);
        TreeNode A = new TreeNode('A',B,C);

        System.out.print("前序：");
        PreOrder(A);
        System.out.println();

        System.out.print("中序：");
        InOrder(A);
        System.out.println();

        System.out.print("后序：");
        PostOrder(A);
        System.out.println();

        System.out.println("深度："+gethight(A));
        System.out.println();

        System.out.println("该树得叶子节点是:"+getLeafCount(A));

    }

    private static int getLeafCount(TreeNode node) {
        if(node==null){
            return 0;
        }

        if(node.left==null && node.night==null){
            return 1;
        }

        return 1+gethight(node.left)+gethight(node.night);
    }

    private static int gethight(TreeNode node) {
        if(node==null){
            return 0;
        }

        if(node.left==null && node.night==null){
            return 1;
        }

        return 1+Math.max(gethight(node.left),gethight(node.night));
    }

    private static void PostOrder(TreeNode node) {
        if(node!=null){
            PreOrder(node.left);
            PreOrder(node.night);
            System.out.print(node.date +"  ");
        }
    }

    private static void InOrder(TreeNode node) {
        if(node!=null){
            InOrder(node.left);
            System.out.print(node.date +"  ");
            InOrder(node.night);
        }
    }

    private static void PreOrder(TreeNode node) {
        if(node!=null){
            System.out.print(node.date +"  ");
            PreOrder(node.left);
            PreOrder(node.night);
        }
    }
}
